<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/28
 * Time: 14:18
 */

namespace app\modules\api\controllers;

use yii;
use yii\web\Controller;
use app\modules\api\service\LoginService;

class LoginController extends Controller
{
    public $enableCsrfValidation = false;

    public function actionIndex()
    {
        $userName = yii::$app->request->post('userName');
        $password = yii::$app->request->post('password');
        if ($userName && $password) {
            $service = new LoginService();
            $res = $service->verify($userName, md5($password));
            if ($res) {
                return json_encode(['code' => 1, 'token' => $res]);
            } else {
                return json_encode(['code' => 0, 'msg' => '用户名或密码错误']);
            }
        } else {
            return json_encode(['code' => 0, 'msg' => '用户名或密码错误']);
        }
    }
}